package com.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.staffDao;

/**
 * Servlet implementation class getAllMsg
 */
@WebServlet("/getAllMsg.do")
public class getAllMsg extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public getAllMsg() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		staffDao dao = new staffDao();
		List<Map> list = dao.selectAllMsg();
		String res = "";
		for(int i=0;i<list.size();i++) {
			Map m = list.get(i);
			res+=m.get("name")+"\u0005";
			res+=m.get("personid")+"\u0005";
			res+=m.get("sex")+"\u0005";
			res+=m.get("nation")+"\u0005";
			res+=m.get("face")+"\u0005";
			res+=m.get("job")+"\u0005";
			res+=m.get("adl")+"\u0005";
			res+=m.get("post")+"\u0005";
			res+=m.get("department")+"\u0005";
			res+=m.get("education")+"\u0005";
			res+=m.get("contact")+"\u0005";
			
			res+=m.get("pid")+"\u0005";
			res+=m.get("kind")+"\u0005";
			res+=m.get("startdate")+"\u0005";
			res+=m.get("enddate")+"\u0005";
			res+=m.get("returndate")+"\u0005";
			
			res+=m.get("country")+"\u0005";
			res+=m.get("college")+"\u0005";
			res+=m.get("outtype")+"\u0005";
			res+=m.get("subject")+"\u0005";
			res+=m.get("outdate")+"\u0005";
			res+=m.get("backdate")+"\u0005";
			res+=m.get("costby")+"\u0005";
			res+=m.get("remake")+"\u0005\u0001";
		}
		res = res.replaceAll("\\{", "");
		res = res.replaceAll("\\}", "");
		res = res.replaceAll("null", "");
		System.out.println(res);
		response.getWriter().print(res);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
